﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Notifications.Interfaces;
using Micrhard.FMCG.Server.Models;
using Microhard.Notifications.Models;
using Micrhard.FMCG.Server.DataAccess;

namespace Micrhard.FMCG.Server.Notification
{
    public class NoticeRec : INotificationScope
    {
        public List<Microhard.Notifications.Models.NotificationUserModel> GetReceivers(object model)
        {
            NoticeModel nm = model as NoticeModel;
            List<NotificationUserModel> result = new List<NotificationUserModel>();
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            if (nm.RecEmployees == null)
            {
                var emps = db.Employees.Where(e => e.CompanyID == nm.CompanyID).ToList();
                emps.ForEach(e =>
                {
                    result.Add(new NotificationUserModel
                    {
                        Mail = e.QQMail
                    });
                });
            }
            else
            {
                nm.RecEmployees.ForEach(e =>
                {
                    var emp = db.Employees.SingleOrDefault(m => m.EmployeeID == e.EmployeeID);
                    result.Add(new NotificationUserModel
                    {
                        Mail = emp.QQMail
                    });
                });
            }
            return result;
        }
    }
}
